<?php

class Account{
    private $user=1;
    private $pwd=2;

    public function __set($name, $value)
    {
//        echo "Setting$name to$value"  . PHP_EOL;
        $this->$name = $value;
    }

    public function __get($name)
    {
        if (!isset($this->$name)) {
//            echo '未设置' . PHP_EOL;
            $this->$name = "正在为你设置默认值";
        }

        return $this->$name;
    }

    /**
     * 魔术方法:本意使动态创建变为可能--未定义函数会调用这个方法
     * @param $name
     * @param $arguments
     */
    public function __call($name, $arguments)
    {
        echo $name, PHP_EOL;

        switch (count($arguments)) {
            case 2:
                echo $arguments[0] . $arguments[1], PHP_EOL;
                break;
            case 3:
                echo array_sum($arguments), PHP_EOL;
                break;
            default:
                echo '参数不对', PHP_EOL;
                break;
        }
    }

    /** 未定义的静态函数会调用这个方法
     * @param $name
     * @param $arguments
     */
    public static function __callStatic($name, $arguments)
    {
        echo 'callStatic function:' . $name . 'argu[0]' . $arguments[0] . PHP_EOL;
    }
}

$a=new Account();
echo $a->user . PHP_EOL;
//echo $a['user'] . PHP_EOL;
$a->name=5;
echo $a->name . PHP_EOL;
echo $a->big . PHP_EOL;
echo '---call--------';
$a->make(5);
$a->make(5,6);
$a->make(5,6,7);
echo '-----------' . PHP_EOL;
echo '---callStatic--------' . PHP_EOL;
echo Account::hello('steven');